<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JModuleLink加载模块</title>
<link rel="stylesheet"
	href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
	integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
	crossorigin="anonymous">
<style type="text/css">
.ms-controller {
	visibility: hidden;
}
</style>
</head>
<body>
	<div class="container ms-controller" style="padding-top: 20px"
		ms-controller="test">
		<div :visible="!!errMsg" class="alert alert-danger" role="alert">{{errMsg}}</div>
		<div>
			<a href="/index.html" class="btn btn-default">列表</a>
		</div>
		<form class="form-horizontal">
			<div class="form-group">
				<label class="col-sm-2 control-label">名称</label>
				<div class="col-sm-10">
					<input ms-duplex="@module.moduleName" class="form-control"
						placeholder="请输入模块名称">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">加载策略</label>
				<div class="col-sm-10">
					<label class="radio-inline"> <input
						ms-duplex="@module.moduleLoadPolicy" value="AbortPolicy" name="moduleLoadPolicy" type="radio">AbortPolicy
					</label> <label class="radio-inline"><input
						ms-duplex="@module.moduleLoadPolicy" value="DiscardPolicy" name="moduleLoadPolicy" type="radio">DiscardPolicy
					</label> <label class="radio-inline"><input
						ms-duplex="@module.moduleLoadPolicy" value="ReplacePolicy" name="moduleLoadPolicy" type="radio">ReplacePolicy
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">描述</label>
				<div class="col-sm-10">
					<input ms-duplex="@module.description" class="form-control"
						placeholder="请输入模块描述">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">类型</label>
				<div class="col-sm-10">
					<label class="radio-inline"> <input
						ms-duplex="@module.type" value="1" name="type" type="radio">Spring XML
					</label> <label class="radio-inline"><input
						ms-duplex="@module.type" value="2" name="type" type="radio">Spring注解
					</label> <label class="radio-inline"><input
						ms-duplex="@module.type" value="3" name="type" type="radio">普通
					</label> <label class="radio-inline"><input
						ms-duplex="@module.type" value="4" name="type" type="radio">SpringBoot
					</label>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-12">
					<button :click="@load" type="button"
						class="btn btn-default btn-block  btn-success">加载</button>
				</div>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="/res/js/avalon.js"></script>
	<script type="text/javascript" src="/res/js/mmRequest.js"></script>
	<script>
		var vm = avalon.define({
			$id : "test",
			module : {
				moduleName : '',
				moduleLoadPolicy : 'AbortPolicy',
				description : '',
				type : '3'
			},
			errMsg : '',
			setErrMsg : function(errMsg) {
				vm.errMsg = errMsg;
				setTimeout(function() {
					vm.errMsg = "";
				}, 2000);
			},
			load : function() {
				var data = vm.$model.module;
				if (!data.moduleName) {
					this.setErrMsg("名称不能为空");
					return;
				}
				avalon.ajax({
					dataType : 'json',
					type : 'POST',
					url : "/loadHandler",
					data : data,
					success : function(data) {
						if (data.errCode == '0') {
							window.location = "/index.html";
						} else {
							vm.setErrMsg(data.errMsg || '加载失败');
						}
					},
					error : function(xhr) {
						vm.setErrMsg(xhr.responseText || '网络错误');
					}
				});
			}
		})
	</script>
</body>
</html>